package com.dk.service.impl;

import com.dk.entity.TContent;
import com.dk.entity.TContentOrder;
import com.dk.mapper.TContentOrderMapper;
import com.dk.service.ITContentOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 广告订单表 服务实现类
 * </p>
 *
 * @author author
 * @since 2021-11-01
 */
@Service
public class TContentOrderServiceImpl extends ServiceImpl<TContentOrderMapper, TContentOrder> implements ITContentOrderService {

    @Autowired
    private TContentOrderMapper tContentOrderMapper;

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @Override
    public Boolean insertContentOrder(TContentOrder tContentOrder, TContent tContent){
        //增加订单
        int insert = tContentOrderMapper.insert(tContentOrder);

        Message<TContent> message = MessageBuilder.withPayload(tContent).build();
        //发送mq异步延时消息
        rocketMQTemplate.syncSend("orderid",message,3000,14);
        if (insert > 0){
            return true;
        }
        return false;
    }
}
